package com.digital.smartgrow.common.advice;

import lombok.Data;

/**
 * 返回结果统一封装实体类
 * @param <T>
 */
@Data
public class Result<T> {
    private int code;
    private String msg;
    private T data;
    private long timestamp;

    public Result(){
        this.timestamp = System.currentTimeMillis();
    }

    public static <T> Result<T> success(T data){
        Result<T> result = new Result<>();
        result.setCode(ReturnCode.RC200.getCode());
        result.setMsg(ReturnCode.RC200.getMessage());
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail(int code,String message){
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMsg(message);
        return result;
    }

    public static <T> Result<T> fail(String message){
        Result<T> result = new Result<>();
        result.setCode(ReturnCode.RC400.getCode());
        result.setMsg(message);
        return result;
    }
}
